package com.sc.web.gwt.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.ui.Button;
import com.sc.web.gwt.client.place.AdministratorWidgetPlace;
import com.sc.web.gwt.client.place.HomeHistoryMapper;
import com.sc.web.gwt.client.place.LoginWidgetPlace;
import com.sc.web.gwt.client.presenter.mapper.HomeActivityMapper;

/**
 * Created by KienCT
 * Date: 29-05-2011
 * Time: 18:44:11
 */
public class Homepage implements EntryPoint {
    private Place defaultPlace = new LoginWidgetPlace();
    private SimplePanel appWidget = new SimplePanel();

    public void onModuleLoad() {
        ClientFactory clientFactory = GWT.create(ClientFactory.class);
        EventBus eventBus = clientFactory.getEventBus();
        PlaceController placeController = clientFactory.getPlaceController();

        // Start ActivityManager for the main widget with our ActivityMapper
        ActivityMapper activityMapper = new HomeActivityMapper(clientFactory);
        ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
        activityManager.setDisplay(appWidget);

        // Start PlaceHistoryHandler with our PlaceHistoryMapper
        HomeHistoryMapper historyMapper = GWT.create(HomeHistoryMapper.class);
        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, defaultPlace);

        RootPanel.get().add(appWidget);
        // Goes to the place represented on URL else default place
        historyHandler.handleCurrentHistory();
    }


//    private FlowPanel loginPanel = new FlowPanel() ;
//
//    private void initializeComponent()  {
//        Label userName = new Label("User Name: ");
//        Label password = new Label("Password: ");
//        password.setStyleName("label");
//        userName.setStyleName("label");
//
//        TextBox fName = new TextBox();
//        PasswordTextBox fPassword = new PasswordTextBox();
//
//        Button loginButton = new Button("Login");
//
//        loginPanel.add(userName);
//        loginPanel.add(fName);
//        loginPanel.add(password);
//        loginPanel.add(fPassword);
//        loginPanel.add(loginButton);
//        RootPanel.get("formPanel").add(loginPanel);
//    }

}
